home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / citsrc6K05.lha / areas.c < prev    next >
C/C++ Source or Header  |  1996-08-29  |  7KB  |  265 lines

  1. /*
  2. *       areas.c
  3. *
  4. * area code for Citadel bulletin board system.
  5. */
  6. /*
  7. *       history
  8. *
  9. * SEE THE INCREM.* FILES FOR FURTHER HISTORICAL NOTES
  10. *
  11. * 89Oct12 HAW  Created from rooma.c.
  12. */
  13. #include "ctdl.h"
  14. /* #include <alloc.h> ***This does not exist, what is in here??***/
  15. /*
  16. *       Contents
  17. *
  18. * DirCheck()    Does this entry already exist in list?
  19. * DirCmp()    Used to sort directory entries.
  20. * DirFree()   frees a directory entry
  21. * fDir()                  prints out a filename for a dir listing
  22. * ShowVerbose()   display of a file for .Read Extended
  23. * wildCard()              expands ambiguous filenames
  24. */
  25. long          FDSize;              /* For accumulating dir. size   */
  26. extern CONFIG    cfg;            /* A buncha variables           */
  27. extern MessageBuffer   msgBuf;
  28. extern char      outFlag;
  29. extern aRoom     roomBuf;        /* room buffer                  */
  30. extern AN_UNSIGNED crtColumn; /* current position on screen           */
  31. extern logBuffer logBuf;         /* Buffer for the pippuls       */
  32. /*
  33. * DirCheck()
  34. *
  35. * Does this entry already exist in the list?  If so, return a pointer to
  36. * the data that matched the data in the list, otherwise NULL.  This is used
  37. * in the list built by wildCard() to cull out duplicate entries, so we
  38. * return s2 rather than s1.
  39. */
  40. void *DirCheck(DirEntry *s1, DirEntry *s2)
  41.   {
  42.   return (strCmpU(s1->unambig, s2->unambig) == 0) ? s2 : NULL;
  43.  
  44.   }
  45. /*
  46. * DirCmp()
  47. *
  48. * This is used by Slist to sort directory entries.
  49. */
  50. int DirCmp(DirEntry *s1, DirEntry *s2)
  51.   {
  52.   return strCmpU(s1->unambig, s2->unambig);
  53.  
  54.   }
  55. /*
  56. * DirFree()
  57. *
  58. * This function frees a directory entry.
  59. */
  60. void DirFree(DirEntry *d)
  61.   {
  62.   free(d->unambig);
  63.   free(d);
  64.  
  65.   }
  66. /*
  67. * fDir()
  68. *
  69. * This function prints out one filename and size for a dir listing.  This
  70. * is the .RD function.
  71. */
  72. void fDir(DirEntry *file)
  73.   {
  74.   long Sectors;
  75.   if (outFlag != OUTOK) return;
  76.   Sectors   = ((file->FileSize + 127) / SECTSIZE);
  77.   FDSize   += Sectors;
  78.   mPrintf("%-15s%5ld%2c", file->unambig, Sectors, ' ');
  79.   mAbort();       /* chance to next(!)/pause/skip */
  80.  
  81.   }
  82. /*
  83. * ShowVerbose()
  84. *
  85. * This function does a display of a file for .Read Extended.
  86. */
  87. void ShowVerbose(DirEntry *file)
  88.   {
  89.   extern int DirAlign;
  90.   extern char AlignChar;
  91.   char *strchr(), *c, found, funnyflag = FALSE, sbuf[100];
  92.   char work[30], *author;
  93.   int  format;
  94.   FILE *fd;
  95.   extern char *READ_ANY;
  96.   extern FunnyInfo Formats[];
  97.   if (outFlag != OUTOK) return;
  98.   FDSize += file->FileSize;
  99.   found = FindFileComment(file->unambig);
  100.   #ifndef TURBO_C_VSPRINTF_BUG
  101.   mPrintf("%-*s%7s ", MAX_FILENAME + 2, file->unambig,
  102.   PrintPretty(file->FileSize, work));
  103.   #else
  104.   mPrintf("%s", file->unambig);
  105.   SpaceBug(MAX_FILENAME + 2 - strLen(file->unambig));
  106.   mPrintf("%7s ", PrintPretty(file->FileSize, work));
  107.   #endif
  108.   format = CompressType(file->unambig);
  109.   if (logBuf.lbflags.ALT_RE)
  110.     {
  111.     mPrintf("|");
  112.     if (found)
  113.       {
  114.       if ((c = strchr(msgBuf.mbtext, '\n')) != NULL) *c = 0;
  115.       DirAlign = 25;
  116.       AlignChar = '|';
  117.       mFormat(strchr(msgBuf.mbtext, ' '));
  118.  
  119.       }
  120.     if (format != ERROR && !Formats[format].Many &&
  121.     Formats[format].Func != NULL)
  122.       {
  123.       fd = fopen(file->unambig, READ_ANY);
  124.       mPrintf(" [");
  125.       (*Formats[format].Func)(fd, FALSE, sbuf);
  126.       mPrintf("%s]", sbuf);
  127.       fclose(fd);
  128.  
  129.       }
  130.     mPrintf(" (%s)", file->FileDate);
  131.  
  132.     }
  133.   else
  134.     {
  135.     mPrintf(" %s", file->FileDate);
  136.     if (format != ERROR && !Formats[format].Many &&
  137.     Formats[format].Func != NULL)
  138.       {
  139.       fd = fopen(file->unambig, READ_ANY);
  140.       mPrintf(" [");
  141.       (*Formats[format].Func)(fd, FALSE, sbuf);
  142.       mPrintf("%s]", sbuf);
  143.       funnyflag = TRUE;
  144.       fclose(fd);
  145.  
  146.       }
  147.     /* the strlen check lets us handle "empty" entries -- found, but */
  148.     /* really nothing there. */
  149.     if ((c = strchr(msgBuf.mbtext, '\n')) != NULL) *c = 0;
  150.     if (found && strlen(strchr(msgBuf.mbtext, ' ')) + crtColumn < logBuf.lbwidth)
  151.     mFormat(strchr(msgBuf.mbtext, ' '));
  152.     else if (found && strlen(strchr(msgBuf.mbtext, ' ')) > 2)
  153.       {
  154.       /* first, we try to parse out author. */
  155.       c = lbyte(msgBuf.mbtext) - 2;
  156.       if (strCmp(c, "].") == SAMESTRING &&
  157.       (author = strrchr(msgBuf.mbtext, '[')) != NULL)
  158.         {
  159.         /* yes! */
  160.         *author++ = 0;  /* null out comment's upload author */
  161.         *c = 0;   /* kill "]." */
  162.         mPrintf(" %sby %s.", (funnyflag) ? "" : "Uploaded ", author);
  163.  
  164.         }
  165.       mPrintf("\n   |");
  166.       DirAlign = 3;
  167.       AlignChar = '|';
  168.       mFormat(strchr(msgBuf.mbtext, ' '));
  169.  
  170.       }
  171.  
  172.     }
  173.   DirAlign = 0;
  174.   doCR();
  175.   mAbort();       /* chance to next(!)/pause/skip */
  176.  
  177.   }
  178. /*
  179. * wildCard()
  180. *
  181. * This function allows generic access to a directory room. The actual actions
  182. * take place via the fn function pointer.  If we're already in the required
  183. * directory area then needToMove should be FALSE.  AssumeDefault is used
  184. * if filename is 0 length -- the *.* or * or whatever is appropriate for
  185. * the system is used to find all the files in the directory.
  186. */
  187. int wildCard(void (*fn)(DirEntry *str), char *filename, char needToMove,
  188. char *phrase, char AssumeDefault)
  189.   {
  190.   extern FILE *netLog;
  191.   int   realCount;
  192.   SListBase LocFiles =
  193.     {
  194.     NULL, DirCheck, DirCmp, DirFree, NULL
  195.  
  196.     };
  197.   char  *DatePtr, *work;
  198.   long  before = -1l, after = -1l;
  199.   if (cfg.BoolFlags.debug)
  200.     {
  201.     splitF(netLog,"wildCard(%08.8X,%08.8X,%X,%08.8X,%X)\n"
  202.     ,fn,filename,needToMove,phrase,AssumeDefault);
  203.  
  204.     };
  205.   /* printf("coreleft at 1 is %ld\n", coreleft()); */
  206.   if (needToMove)
  207.   if (!setSpace(&roomBuf))
  208.     {
  209.       if (cfg.BoolFlags.debug)
  210.          printf("setSpace failed!\n");
  211.     return 0;
  212.  
  213.     }
  214.   /* printf("coreleft at 2 is %ld\n", coreleft()); */
  215.   work = strdup(filename);
  216.   /* printf("coreleft at 3 is %ld\n", coreleft()); */
  217.   if ((DatePtr = DateSearch(work, &before, &after)) != NULL)
  218.   DateSearch(DatePtr, &before, &after);
  219.   /* printf("coreleft at 4 is %ld\n", coreleft()); */
  220.   if (AssumeDefault && strLen(work) == 0)
  221.     {
  222.     free(work);
  223.     work = strdup(ALL_FILES);
  224.  
  225.     }
  226.   /* printf("coreleft at 5 is %ld\n", coreleft()); */
  227.   CitGetFileList(work, &LocFiles, before, after, phrase);
  228.   /* printf("coreleft at 6 is %ld\n", coreleft()); */
  229.   realCount = wild2Card(&LocFiles, fn);
  230.   /* printf("coreleft at 6.1 is %ld\n", coreleft()); */
  231.   KillList(&LocFiles);
  232.   /* printf("coreleft at 7 is %ld\n", coreleft()); */
  233.   if (needToMove) homeSpace();
  234.   free(work);
  235.   /* printf("coreleft at 8 is %ld\n", coreleft()); */
  236.   return realCount;
  237.  
  238.   }
  239. /*
  240. * wild2Card()
  241. *
  242. * integrate this back into wildCard() someday.
  243. */
  244. int wild2Card(SListBase *Files, void (*fn)())
  245.   {
  246.   int Count;
  247.   outFlag     = OUTOK;
  248.   StFileComSearch();
  249.   Count = RunList(Files, fn);
  250.   EndFileComment();
  251.   return Count;
  252.  
  253.   }
  254. /*
  255. * getSize()
  256. *
  257. * This function gets the size of the file from the actual directory entry.
  258. */
  259. void getSize(DirEntry *file)
  260.   {
  261.   extern long netBytes;
  262.   netBytes += file->FileSize;
  263.  
  264.   }
  265.